package com.ruoyi.fjtseac.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fjtseac.domain.dto.AudioDto;
import com.ruoyi.fjtseac.service.AudioService;
import com.ruoyi.fjtseac.util.aop.RedisCacheClear;
import com.ruoyi.fjtseac.util.aop.RedisCacheEnable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.common.core.controller.BaseController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

/**
 * 音频Controller
 *
 * @author icyrain11
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/audio")
@Api(tags = {"音频接口"})
@Validated
public class AudioController {

    @Autowired
    private AudioService audioService;

    @PreAuthorize("@ss.hasPermi('fjtseac:audio:upload')")
    @RedisCacheClear
    @PostMapping(headers = "content-type=multipart/form-data")
    @ApiOperation("音频上传")
    public AjaxResult upload(AudioDto audioDto, @ApiParam("音频进度唯一标识") @RequestParam @NotBlank String uuid) {
        return audioService.upload(audioDto, uuid);
    }

    @PreAuthorize("@ss.hasPermi('fjtseac:audio:remove')")
    @RedisCacheClear
    @DeleteMapping
    @ApiOperation("音频删除")
    public AjaxResult delete(@ApiParam(value = "所要删除的音频id") @RequestParam @Min(value = 1) Integer audioId) {
        return audioService.delete(audioId);
    }


    @RedisCacheEnable
    @GetMapping
    @ApiOperation("分页获取全部音频，根据音频名模糊搜索")
    public AjaxResult search(@ApiParam("搜索关键词") String param,
                             @ApiParam("当前页码") @RequestParam int pageNum,
                             @ApiParam("页面最大记录数") @RequestParam int pageSize) {

        return audioService.search(param, pageNum, pageSize);
    }


    @GetMapping("/progress")
    @ApiOperation("音频获取进度")
    public AjaxResult progress(@ApiParam(value = "音频进度唯一标识", required = true) @NotBlank String uuid) {
        return audioService.getProgress(uuid);
    }
}
